<template>
	<view class="body">
		<xk-header title="巡查异常处理"></xk-header>
		<view class="list" >
			<view class="list-item header" @click="more = !more">
				<view>巡查单号:  {{data.task_no}}</view>
				<image v-if="!more" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="more" class="data-item">
				<view class="order-info">
					<view class="info-item"><view class="key">路线名称：</view>{{data.route_name}}</view>
					<view class="info-item"><view class="key">巡查事项：</view>{{data.standard_name}}</view>
					<view class="info-item"><view class="key">巡查时段：</view>{{data.plan_start_time}} - {{data.plan_end_time | formatTime}}</view>
				</view>
			</view>
		</view>

		<view class="list" >
			<view class="list-item header" @click="orderMore = !orderMore">
				<view>巡查记录</view>
				<image v-if="!orderMore" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="orderMore" class="data-item">
				<view class="order-info">
					<view class="info-item"><view class="key">巡查结果：</view>异常</view>
					<view @click="viewDetail" class="info-item" style="justify-content: space-between;">
						<view class="key">巡查详情：</view>
						<view style="display: flex; align-items: center;">
							<text class="right-title1" style="color: #2C72FF;">查看明细</text>
							<image mode="aspectFill" class="jiantou" src="/static/jiantou.png"/>
						</view>
					</view>
					<view class="info-item"><view class="key">完成时间：</view>{{data.finish_time}}</view>
					<view class="info-item"><view class="key">异常描述：</view><text>{{data.patrol_remark}}</text></view>
					<!-- <view class="info-item"><view class="key"></view>
						<image-list :pics="'/static/temp/temp.jpeg'"></image-list>
					</view> -->
				</view>
			</view>
		</view>

		<view class="list">
			<view class="list-item header">
				<view>异常处理</view>
			</view>
			<view>
				<!-- <biaofun-datetime-picker :defaultValue="defaultDate"
					start="2000-02-03 00:00"
					end="2200-10-28 23:59"
					fields="minute"
					@change="dealTimeChange"
				>
					<view class="list-item">
						<view>处理时间：</view>
						<view :class="formInfo.finish_time ? 'right-title1' : 'right-title1 right-title1-empty'">{{formInfo.finish_time ? formInfo.finish_time : "请选择"}}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png"/>
					</view>
				</biaofun-datetime-picker> -->

				<view class="list-item">
					<view>处理方案<text class="com-req"></text>：</view>
					<input class="input-item" v-model="formInfo.deal_program" placeholder="请输入处理方案" placeholder-class="placeholder"/>
				</view>
				<view class="list-item textarea">
					<view>备注：</view>
					<textarea v-model="formInfo.deal_remark" placeholder="在此输入备注" placeholder-class="placeholder"/>
				</view>
			</view>
		</view>
		<!-- <view class="upload-img-item">
			<view class="title">上传巡查照片</view>
			<upload-image images="" @onChange="uploadImageChange"/>
		</view> -->
		<view class="common-bottom-view">
			<view class="common-btn" @click="doneRepair">提交</view>
		</view>
		<view class="common-zw"></view>


	</view>
</template>

<script>
	import moment from 'moment'
	export default {
		data() {
			return {
				taskId: '',
				dets: {},
				data: {},
				more: true,
				orderMore: true,
				defaultDate: moment().format('YYYY-MM-DD HH:mm'),
				formInfo: {
				    task_id: "",
				    deal_program: "",
				    deal_remark: "",
				    isSubmit: true
				},
				notNull: {
					deal_program: "处理方案",
				}
			};
		},
		onLoad(options) {
			this.taskId = options.taskId
			this.formInfo.task_id = this.taskId
			this.getData();
		},

		methods:{
			getData(){
				this.$api.baseData_getPmPatrolTask(this.taskId).then((res)=>{
					this.data = res.task
					let num = 1;
					for(let index in this.data.dets){
						let item = this.data.dets[index]
						if(this.dets[item.property_code]){
							this.dets[item.property_code].data.push(item)
						}else{
							this.dets[item.property_code] = {
								num: num,
								building: item.property_building,
								storey: item.property_storey,
								room: item.property_room,
								data: [item]
							}
							num++;
						}
					}
				})
			},
			viewDetail(){
				uni.navigateTo({
					url: '/pagesA/build-patrol/build-patrol-result-detail?dets=' + JSON.stringify(this.dets)
				})
			},
			dealTimeChange(e){
				this.formInfo.finish_time = moment(e.dt).format('YYYY-MM-DD HH:mm')
			},
			doneRepair(){
				for (let item in this.notNull) {
					if (!this.formInfo[item]) {
						this.$util.toast(this.notNull[item]);
						return;
					}
				}
				this.$util.confirm({
					content: "确定提交？",
					confirmText: "确认"
				}).then(isConfirm => {
					if (isConfirm) {
						this.$util.post({
							url: "app/pmPatrolTask/deal",
							data: this.formInfo
						}).then(res => {
							uni.$emit('refreshHomeDataList')
							uni.$emit('refreshPatrolTask')
							uni.redirectTo({
								url: '/pagesA/build-patrol/build-patrol-finish?type=fix'
							})
						})

					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
@import '@/common/from.scss';

</style>
